
****************
**DHS Combined**
****************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/DHS/DHS Combined Data.dta", clear

drop if hhage<=19
drop if hhage >=60

gen tens = 0
replace tens=1 if hhage == 20 | hhage == 30 | hhage == 40 | hhage == 50 | hhage == 60| hhage == 70| hhage == 80
gen fives = 0
replace five=1 if hhage == 25 | hhage == 35 | hhage == 45 | hhage == 55 | hhage == 65 | hhage == 75
gen ones = 0
replace ones=1 if hhage == 21 | hhage == 31 | hhage == 41 | hhage == 51 | hhage == 61| hhage == 71| hhage == 81
gen twos = 0
replace twos=1 if hhage == 22 | hhage == 32 | hhage == 42 | hhage == 52 | hhage == 62| hhage == 72| hhage == 82
gen threes = 0
replace threes=1 if hhage == 23 | hhage == 33 | hhage == 43 | hhage == 53 | hhage == 63| hhage == 73| hhage == 83
gen fours = 0
replace fours=1 if hhage == 24 | hhage == 34 | hhage == 44 | hhage == 54 | hhage == 64| hhage == 74| hhage == 84
gen sixes = 0
replace sixes=1 if hhage == 26 | hhage == 36 | hhage == 46 | hhage == 56 | hhage == 66| hhage == 76| hhage == 86
gen sevens = 0
replace sevens=1 if hhage == 27 | hhage == 37 | hhage == 47 | hhage == 57 | hhage == 67| hhage == 77| hhage == 87
gen eights = 0
replace eights=1 if hhage == 28 | hhage == 38 | hhage == 48 | hhage == 58 | hhage == 68| hhage == 78| hhage == 88
gen nines = 0
replace nines=1 if hhage == 29 | hhage == 39 | hhage == 49 | hhage == 59 | hhage == 69| hhage == 79| hhage == 89

gen twenties = 0
replace twenties = 1 if hhage>=20 & hhage<=29
gen thirties = 0
replace thirties = 1 if hhage>=30 & hhage<=39
gen forties = 0
replace forties = 1 if hhage>=40 & hhage<=49
gen fifties = 0
replace fifties = 1 if hhage>=50 & hhage<=59
gen sixties = 0
replace sixties = 1 if hhage>=60 & hhage<=69
gen seventies = 0
replace seventies = 1 if hhage>=70 & hhage<=79

gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1

gen zero_or_five = 0
replace zero_or_five = 1 if digit==0 | digit==5

*Figure 1a*
histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)

*Myers Index, DHS*
myers hhage, range(20 59)

*************************
**Afrobarometer Round 6**
*************************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/Afrobarometer/Data and Codebooks/merged_r6_data_2016_36countries2.dta", clear

drop if Q1<=19
drop if Q1 >=60

gen tens = 0
replace tens=1 if Q1 == 20 | Q1 == 30 | Q1 == 40 | Q1 == 50 | Q1 == 60| Q1 == 70| Q1 == 80
gen fives = 0
replace five=1 if Q1 == 25 | Q1 == 35 | Q1 == 45 | Q1 == 55 | Q1 == 65 | Q1 == 75
gen ones = 0
replace ones=1 if Q1 == 21 | Q1 == 31 | Q1 == 41 | Q1 == 51 | Q1 == 61| Q1 == 71| Q1 == 81
gen twos = 0
replace twos=1 if Q1 == 22 | Q1 == 32 | Q1 == 42 | Q1 == 52 | Q1 == 62| Q1 == 72| Q1 == 82
gen threes = 0
replace threes=1 if Q1 == 23 | Q1 == 33 | Q1 == 43 | Q1 == 53 | Q1 == 63| Q1 == 73| Q1 == 83
gen fours = 0
replace fours=1 if Q1 == 24 | Q1 == 34 | Q1 == 44 | Q1 == 54 | Q1 == 64| Q1 == 74| Q1 == 84
gen sixes = 0
replace sixes=1 if Q1 == 26 | Q1 == 36 | Q1 == 46 | Q1 == 56 | Q1 == 66| Q1 == 76| Q1 == 86
gen sevens = 0
replace sevens=1 if Q1 == 27 | Q1 == 37 | Q1 == 47 | Q1 == 57 | Q1 == 67| Q1 == 77| Q1 == 87
gen eights = 0
replace eights=1 if Q1 == 28 | Q1 == 38 | Q1 == 48 | Q1 == 58 | Q1 == 68| Q1 == 78| Q1 == 88
gen nines = 0
replace nines=1 if Q1 == 29 | Q1 == 39 | Q1 == 49 | Q1 == 59 | Q1 == 69| Q1 == 79| Q1 == 89

gen twenties = 0
replace twenties = 1 if Q1>=20 & Q1<=29
gen thirties = 0
replace thirties = 1 if Q1>=30 & Q1<=39
gen forties = 0
replace forties = 1 if Q1>=40 & Q1<=49
gen fifties = 0
replace fifties = 1 if Q1>=50 & Q1<=59
gen sixties = 0
replace sixties = 1 if Q1>=60 & Q1<=69
gen seventies = 0
replace seventies = 1 if Q1>=70 & Q1<=79


gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1


gen zero_or_five = 0
replace zero_or_five = 1 if digit==0 | digit==5

*Figure 1b*
histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)

*Myers Index, Afrobarometer R6*
myers Q1, range(20 59)

*************
**ANES 2016**
*************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/anes_timeseries_2016_dta/anes_timeseries_2016_Stata12.dta", clear

drop if V161267<=19
drop if V161267 >=60

gen tens = 0
replace tens=1 if V161267 == 20 | V161267 == 30 | V161267 == 40 | V161267 == 50 | V161267 == 60| V161267 == 70| V161267 == 80
gen fives = 0
replace five=1 if V161267 == 25 | V161267 == 35 | V161267 == 45 | V161267 == 55 | V161267 == 65 | V161267 == 75
gen ones = 0
replace ones=1 if V161267 == 21 | V161267 == 31 | V161267 == 41 | V161267 == 51 | V161267 == 61| V161267 == 71| V161267 == 81
gen twos = 0
replace twos=1 if V161267 == 22 | V161267 == 32 | V161267 == 42 | V161267 == 52 | V161267 == 62| V161267 == 72| V161267 == 82
gen threes = 0
replace threes=1 if V161267 == 23 | V161267 == 33 | V161267 == 43 | V161267 == 53 | V161267 == 63| V161267 == 73| V161267 == 83
gen fours = 0
replace fours=1 if V161267 == 24 | V161267 == 34 | V161267 == 44 | V161267 == 54 | V161267 == 64| V161267 == 74| V161267 == 84
gen sixes = 0
replace sixes=1 if V161267 == 26 | V161267 == 36 | V161267 == 46 | V161267 == 56 | V161267 == 66| V161267 == 76| V161267 == 86
gen sevens = 0
replace sevens=1 if V161267 == 27 | V161267 == 37 | V161267 == 47 | V161267 == 57 | V161267 == 67| V161267 == 77| V161267 == 87
gen eights = 0
replace eights=1 if V161267 == 28 | V161267 == 38 | V161267 == 48 | V161267 == 58 | V161267 == 68| V161267 == 78| V161267 == 88
gen nines = 0
replace nines=1 if V161267 == 29 | V161267 == 39 | V161267 == 49 | V161267 == 59 | V161267 == 69| V161267 == 79| V161267 == 89

gen twenties = 0
replace twenties = 1 if V161267>=20 & V161267<=29
gen thirties = 0
replace thirties = 1 if V161267>=30 & V161267<=39
gen forties = 0
replace forties = 1 if V161267>=40 & V161267<=49
gen fifties = 0
replace fifties = 1 if V161267>=50 & V161267<=59
gen sixties = 0
replace sixties = 1 if V161267>=60 & V161267<=69
gen seventies = 0
replace seventies = 1 if V161267>=70 & V161267<=79

gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1

*Figure 1c*
histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)

*Myers Index, ANES*
myers V161267, range(20 59)


************
**GSS 2018**
************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/GSS/GSS2018.dta", clear

drop if age<=19
drop if age >=60

gen tens = 0
replace tens=1 if age == 20 | age == 30 | age == 40 | age == 50 | age == 60| age == 70| age == 80
gen fives = 0
replace five=1 if age == 25 | age == 35 | age == 45 | age == 55 | age == 65 | age == 75
gen ones = 0
replace ones=1 if age == 21 | age == 31 | age == 41 | age == 51 | age == 61| age == 71| age == 81
gen twos = 0
replace twos=1 if age == 22 | age == 32 | age == 42 | age == 52 | age == 62| age == 72| age == 82
gen threes = 0
replace threes=1 if age == 23 | age == 33 | age == 43 | age == 53 | age == 63| age == 73| age == 83
gen fours = 0
replace fours=1 if age == 24 | age == 34 | age == 44 | age == 54 | age == 64| age == 74| age == 84
gen sixes = 0
replace sixes=1 if age == 26 | age == 36 | age == 46 | age == 56 | age == 66| age == 76| age == 86
gen sevens = 0
replace sevens=1 if age == 27 | age == 37 | age == 47 | age == 57 | age == 67| age == 77| age == 87
gen eights = 0
replace eights=1 if age == 28 | age == 38 | age == 48 | age == 58 | age == 68| age == 78| age == 88
gen nines = 0
replace nines=1 if age == 29 | age == 39 | age == 49 | age == 59 | age == 69| age == 79| age == 89

gen twenties = 0
replace twenties = 1 if age>=20 & age<=29
gen thirties = 0
replace thirties = 1 if age>=30 & age<=39
gen forties = 0
replace forties = 1 if age>=40 & age<=49
gen fifties = 0
replace fifties = 1 if age>=50 & age<=59
gen sixties = 0
replace sixties = 1 if age>=60 & age<=69
gen seventies = 0
replace seventies = 1 if age>=70 & age<=79

gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1

*Figure 1d*
histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)

*Myers Index, GSS*
myers age, range(20 59)

*************************
**Afrobarometer Round 2**
*************************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/Afrobarometer/Data and Codebooks/merged_r2_data.dta", clear

drop if q80<=19
drop if q80 >=60

gen tens = 0
replace tens=1 if q80 == 20 | q80 == 30 | q80 == 40 | q80 == 50 | q80 == 60| q80 == 70| q80 == 80
gen fives = 0
replace five=1 if q80 == 25 | q80 == 35 | q80 == 45 | q80 == 55 | q80 == 65 | q80 == 75
gen ones = 0
replace ones=1 if q80 == 21 | q80 == 31 | q80 == 41 | q80 == 51 | q80 == 61| q80 == 71| q80 == 81
gen twos = 0
replace twos=1 if q80 == 22 | q80 == 32 | q80 == 42 | q80 == 52 | q80 == 62| q80 == 72| q80 == 82
gen threes = 0
replace threes=1 if q80 == 23 | q80 == 33 | q80 == 43 | q80 == 53 | q80 == 63| q80 == 73| q80 == 83
gen fours = 0
replace fours=1 if q80 == 24 | q80 == 34 | q80 == 44 | q80 == 54 | q80 == 64| q80 == 74| q80 == 84
gen sixes = 0
replace sixes=1 if q80 == 26 | q80 == 36 | q80 == 46 | q80 == 56 | q80 == 66| q80 == 76| q80 == 86
gen sevens = 0
replace sevens=1 if q80 == 27 | q80 == 37 | q80 == 47 | q80 == 57 | q80 == 67| q80 == 77| q80 == 87
gen eights = 0
replace eights=1 if q80 == 28 | q80 == 38 | q80 == 48 | q80 == 58 | q80 == 68| q80 == 78| q80 == 88
gen nines = 0
replace nines=1 if q80 == 29 | q80 == 39 | q80 == 49 | q80 == 59 | q80 == 69| q80 == 79| q80 == 89

gen twenties = 0
replace twenties = 1 if q80>=20 & q80<=29
gen thirties = 0
replace thirties = 1 if q80>=30 & q80<=39
gen forties = 0
replace forties = 1 if q80>=40 & q80<=49
gen fifties = 0
replace fifties = 1 if q80>=50 & q80<=59
gen sixties = 0
replace sixties = 1 if q80>=60 & q80<=69
gen seventies = 0
replace seventies = 1 if q80>=70 & q80<=79

gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1

histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)


*************************
**Afrobarometer Round 3**
*************************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/Afrobarometer/Data and Codebooks/merged_r3_data.dta", clear

drop if q1<=19
drop if q1 >=60

gen tens = 0
replace tens=1 if q1 == 20 | q1 == 30 | q1 == 40 | q1 == 50 | q1 == 60| q1 == 70| q1 == 80
gen fives = 0
replace five=1 if q1 == 25 | q1 == 35 | q1 == 45 | q1 == 55 | q1 == 65 | q1 == 75
gen ones = 0
replace ones=1 if q1 == 21 | q1 == 31 | q1 == 41 | q1 == 51 | q1 == 61| q1 == 71| q1 == 81
gen twos = 0
replace twos=1 if q1 == 22 | q1 == 32 | q1 == 42 | q1 == 52 | q1 == 62| q1 == 72| q1 == 82
gen threes = 0
replace threes=1 if q1 == 23 | q1 == 33 | q1 == 43 | q1 == 53 | q1 == 63| q1 == 73| q1 == 83
gen fours = 0
replace fours=1 if q1 == 24 | q1 == 34 | q1 == 44 | q1 == 54 | q1 == 64| q1 == 74| q1 == 84
gen sixes = 0
replace sixes=1 if q1 == 26 | q1 == 36 | q1 == 46 | q1 == 56 | q1 == 66| q1 == 76| q1 == 86
gen sevens = 0
replace sevens=1 if q1 == 27 | q1 == 37 | q1 == 47 | q1 == 57 | q1 == 67| q1 == 77| q1 == 87
gen eights = 0
replace eights=1 if q1 == 28 | q1 == 38 | q1 == 48 | q1 == 58 | q1 == 68| q1 == 78| q1 == 88
gen nines = 0
replace nines=1 if q1 == 29 | q1 == 39 | q1 == 49 | q1 == 59 | q1 == 69| q1 == 79| q1 == 89

gen twenties = 0
replace twenties = 1 if q1>=20 & q1 <=29
gen thirties = 0
replace thirties = 1 if q1>=30 & q1 <=39
gen forties = 0
replace forties = 1 if q1>=40 & q1 <=49
gen fifties = 0
replace fifties = 1 if q1>=50 & q1 <=59
gen sixties = 0
replace sixties = 1 if q1>=60 & q1 <=69
gen seventies = 0
replace seventies = 1 if q1>=70 & q1 <=79


gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1


gen zero_or_five = 0
replace zero_or_five = 1 if digit==0 | digit==5

histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)


*************************
**Afrobarometer Round 4**
*************************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/Afrobarometer/Data and Codebooks/merged_r4_data.dta", clear

drop if q1<=19
drop if q1 >=60

gen tens = 0
replace tens=1 if q1 == 20 | q1 == 30 | q1 == 40 | q1 == 50 | q1 == 60| q1 == 70| q1 == 80
gen fives = 0
replace five=1 if q1 == 25 | q1 == 35 | q1 == 45 | q1 == 55 | q1 == 65 | q1 == 75
gen ones = 0
replace ones=1 if q1 == 21 | q1 == 31 | q1 == 41 | q1 == 51 | q1 == 61| q1 == 71| q1 == 81
gen twos = 0
replace twos=1 if q1 == 22 | q1 == 32 | q1 == 42 | q1 == 52 | q1 == 62| q1 == 72| q1 == 82
gen threes = 0
replace threes=1 if q1 == 23 | q1 == 33 | q1 == 43 | q1 == 53 | q1 == 63| q1 == 73| q1 == 83
gen fours = 0
replace fours=1 if q1 == 24 | q1 == 34 | q1 == 44 | q1 == 54 | q1 == 64| q1 == 74| q1 == 84
gen sixes = 0
replace sixes=1 if q1 == 26 | q1 == 36 | q1 == 46 | q1 == 56 | q1 == 66| q1 == 76| q1 == 86
gen sevens = 0
replace sevens=1 if q1 == 27 | q1 == 37 | q1 == 47 | q1 == 57 | q1 == 67| q1 == 77| q1 == 87
gen eights = 0
replace eights=1 if q1 == 28 | q1 == 38 | q1 == 48 | q1 == 58 | q1 == 68| q1 == 78| q1 == 88
gen nines = 0
replace nines=1 if q1 == 29 | q1 == 39 | q1 == 49 | q1 == 59 | q1 == 69| q1 == 79| q1 == 89

gen twenties = 0
replace twenties = 1 if q1>=20 & q1 <=29
gen thirties = 0
replace thirties = 1 if q1>=30 & q1 <=39
gen forties = 0
replace forties = 1 if q1>=40 & q1 <=49
gen fifties = 0
replace fifties = 1 if q1>=50 & q1 <=59
gen sixties = 0
replace sixties = 1 if q1>=60 & q1 <=69
gen seventies = 0
replace seventies = 1 if q1>=70 & q1 <=79


gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1


gen zero_or_five = 0
replace zero_or_five = 1 if digit==0 | digit==5

histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)


*************************
**Afrobarometer Round 5**
*************************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/Afrobarometer/Data and Codebooks/merged-round-5-data-34-countries-2011-2013-last-update-july-2015.dta", clear

drop if Q1<=19
drop if Q1 >=60

gen tens = 0
replace tens=1 if Q1 == 20 | Q1 == 30 | Q1 == 40 | Q1 == 50 | Q1 == 60| Q1 == 70| Q1 == 80
gen fives = 0
replace five=1 if Q1 == 25 | Q1 == 35 | Q1 == 45 | Q1 == 55 | Q1 == 65 | Q1 == 75
gen ones = 0
replace ones=1 if Q1 == 21 | Q1 == 31 | Q1 == 41 | Q1 == 51 | Q1 == 61| Q1 == 71| Q1 == 81
gen twos = 0
replace twos=1 if Q1 == 22 | Q1 == 32 | Q1 == 42 | Q1 == 52 | Q1 == 62| Q1 == 72| Q1 == 82
gen threes = 0
replace threes=1 if Q1 == 23 | Q1 == 33 | Q1 == 43 | Q1 == 53 | Q1 == 63| Q1 == 73| Q1 == 83
gen fours = 0
replace fours=1 if Q1 == 24 | Q1 == 34 | Q1 == 44 | Q1 == 54 | Q1 == 64| Q1 == 74| Q1 == 84
gen sixes = 0
replace sixes=1 if Q1 == 26 | Q1 == 36 | Q1 == 46 | Q1 == 56 | Q1 == 66| Q1 == 76| Q1 == 86
gen sevens = 0
replace sevens=1 if Q1 == 27 | Q1 == 37 | Q1 == 47 | Q1 == 57 | Q1 == 67| Q1 == 77| Q1 == 87
gen eights = 0
replace eights=1 if Q1 == 28 | Q1 == 38 | Q1 == 48 | Q1 == 58 | Q1 == 68| Q1 == 78| Q1 == 88
gen nines = 0
replace nines=1 if Q1 == 29 | Q1 == 39 | Q1 == 49 | Q1 == 59 | Q1 == 69| Q1 == 79| Q1 == 89

gen twenties = 0
replace twenties = 1 if Q1>=20 & Q1<=29
gen thirties = 0
replace thirties = 1 if Q1>=30 & Q1<=39
gen forties = 0
replace forties = 1 if Q1>=40 & Q1<=49
gen fifties = 0
replace fifties = 1 if Q1>=50 & Q1<=59
gen sixties = 0
replace sixties = 1 if Q1>=60 & Q1<=69
gen seventies = 0
replace seventies = 1 if Q1>=70 & Q1<=79


gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1


gen zero_or_five = 0
replace zero_or_five = 1 if digit==0 | digit==5

histogram digit, discrete percent ylabel(0(2)20) xtitle(Digit) xlabel(0(1)9)

*****************************************
**Individual correlates of irregularity**
*****************************************

use "/Users/stevenrosenzweig/Dropbox/Research/Age Survey Validity/DHS/DHS Combined Data.dta", clear

gen tens = 0
replace tens=1 if hhage == 0 | hhage==10 | hhage== 20 | hhage == 30 | hhage == 40 | hhage == 50 | hhage == 60| hhage == 70| hhage == 80
gen fives = 0
replace five=1 if hhage == 5 | hhage == 15 | hhage == 25 | hhage == 35 | hhage == 45 | hhage == 55 | hhage == 65 | hhage == 75
gen ones = 0
replace ones=1 if hhage == 1 | hhage == 11 | hhage == 21 | hhage == 31 | hhage == 41 | hhage == 51 | hhage == 61| hhage == 71| hhage == 81
gen twos = 0
replace twos=1 if hhage == 2 | hhage == 12 | hhage == 22 | hhage == 32 | hhage == 42 | hhage == 52 | hhage == 62| hhage == 72| hhage == 82
gen threes = 0
replace threes=1 if hhage == 3 | hhage == 13 | hhage == 23 | hhage == 33 | hhage == 43 | hhage == 53 | hhage == 63| hhage == 73| hhage == 83
gen fours = 0
replace fours=1 if hhage == 4 | hhage == 14 | hhage == 24 | hhage == 34 | hhage == 44 | hhage == 54 | hhage == 64| hhage == 74| hhage == 84
gen sixes = 0
replace sixes=1 if hhage == 6 | hhage == 16 | hhage == 26 | hhage == 36 | hhage == 46 | hhage == 56 | hhage == 66| hhage == 76| hhage == 86
gen sevens = 0
replace sevens=1 if hhage == 7 | hhage == 17 | hhage == 27 | hhage == 37 | hhage == 47 | hhage == 57 | hhage == 67| hhage == 77| hhage == 87
gen eights = 0
replace eights=1 if hhage == 8 | hhage == 18 | hhage == 28 | hhage == 38 | hhage == 48 | hhage == 58 | hhage == 68| hhage == 78| hhage == 88
gen nines = 0
replace nines=1 if hhage == 9 | hhage == 19 | hhage == 29 | hhage == 39 | hhage == 49 | hhage == 59 | hhage == 69| hhage == 79| hhage == 89

gen twenties = 0
replace twenties = 1 if hhage>=20 & hhage<=29
gen thirties = 0
replace thirties = 1 if hhage>=30 & hhage<=39
gen forties = 0
replace forties = 1 if hhage>=40 & hhage<=49
gen fifties = 0
replace fifties = 1 if hhage>=50 & hhage<=59
gen sixties = 0
replace sixties = 1 if hhage>=60 & hhage<=69
gen seventies = 0
replace seventies = 1 if hhage>=70 & hhage<=79

gen digit = 0
replace digit = 1 if ones==1
replace digit = 2 if twos==1
replace digit = 3 if threes==1
replace digit = 4 if fours==1
replace digit = 5 if fives==1
replace digit = 6 if sixes==1
replace digit = 7 if sevens==1
replace digit = 8 if eights==1
replace digit = 9 if nines==1

gen zero_or_five = 0
replace zero_or_five = 1 if digit==0 | digit==5

gen str2 country = substr(dhsid, 1, 2)
encode country, gen(ccode)
gen year = substr(dhsid, 3, 4)
destring year, replace

replace hhbirth = . if hhbirth==7 | hhbirth==8 | hhbirth==9
*Benin and Nigeria only reported Registered vs unregistered births for these years, so they're thrown out
replace hhbirth = . if ccode==3 & year==2006
replace hhbirth = . if ccode==18 & year==2013
*Recode registration only as no birth certificate
replace hhbirth = 0 if hhbirth==2

replace sex = . if sex==8
replace sex = sex-1
label define malefemale 0 "male" 1 "female"
label values sex malefemale

replace urbanhh = urbanhh-1
label define ruralurban 0 "urban" 1 "rural"
label values urbanhh ruralurban

replace edyears = . if edyears>=90

lab var urban "Rural"
lab var sex "Female"

*Table 1*
estpost ttest hhbirthcert urban sex wealthshh hhage edyears, by(zero_or) unequal

*Appendix Table B1*
estpost correlate zero_or hhbirthcert urban sex wealthshh hhage edyears [pweight=hhweight]

********************************************
**Correlates of country-level irregularity**
********************************************

egen countrysurvey = group(ccode year)

collapse (mean) hhbirthcert urban sex wealthshh hhage edyears zero_or year ccode [pweight=hhweight], by(countrysurvey)

*Table 2*
reg zero_or hhbirthcert urban wealthshh hhage edyears
reg zero_or urban wealthshh hhage edyears
